package Class_03_22;

import java.util.Scanner;

public class BookTest {
    public static void main(String[] args) {
        Book[] books = new Book[3];
        Book[] Buybooks = new Book[3];
        books[0] = new Book(1,"Java教程",30.6,30);
        books[1] = new Book(2,"JSP教程",42.1,40);
        books[2] = new Book(3,"SSH架构",47.3,15);
        menu(books);
        double sum = 0;
        for (int i = 0; i < books.length; i++) {
            Buybooks[i] = ways(books);
            sum += Buybooks[i].getPrice() * (books[i].getInventory() - Buybooks[i].getInventory());
            System.out.println("请继续输入");
        }
        Print(Buybooks);
        System.out.println("总金额为" + sum);

    }

    public static void menu(Book[] books)
    {
        System.out.println("----------------------------------");
        for (int i = 0; i < books.length; i++) {
            System.out.println(books[i].getNum() + "  " + books[i].getName() + "  " + books[i].getPrice() + "  " + books[i].getInventory());
        }
        System.out.println("----------------------------------");
    }

    public static Book ways(Book[] books)
    {
        Book book = new Book();
        System.out.println("请输入图书编号进行选择图书");
        Scanner sc = new Scanner(System.in);
        int id = sc.nextInt() - 1;
        System.out.println("请输入购买图书的数量");
        int num = sc.nextInt();
        book.setName(books[id].getName());
        book.setPrice(books[id].getPrice());
        book.setInventory(books[id].getInventory()-num);
        return book;
    }

    public static void Print(Book[] Buybooks)
    {
        System.out.println("----------------------------------");
        for (int i = 0; i < Buybooks.length; i++) {
            System.out.println(Buybooks[i].getNum() + "  " + Buybooks[i].getName() + "  " + Buybooks[i].getPrice() + "  " + Buybooks[i].getInventory());
        }
        System.out.println("----------------------------------");
    }
}
